<?php
include_once('main_global.php');
bn_include_lib('bn_jquery');
$gad=new bn_gadget;
$post=new bn_post;
$cmnt=new bn_comment;
$gf=new bn_genralfunc;
$theme->add_block('body');
$pid=$gf->Get_number($_GET['pid']);
if(isset($pid))
{
  $row=$post->get_post($pid)->fetch();
  if(empty($row)||$row['status']=='disable') 
  bn_redirect('sample.php'); 
}
else
bn_redirect('sample.php');
?>
<label><?php echo $row['title'] ?></label>
<br /><br />
<span><?php echo $row['text'] ?></span>
<br /><br />
<label>نویسنده:</label><label><?php echo $row['user'] ?></label><label>پست شده در تاریخ: </label><label><?php echo $row['date'] ?></label>
<div id="comment">
<?php 
if($row['comment']=='enable')
{
    $theme->add_script(jquery_submit_show('#submit','submit','#cmnt'));
    $grid=new bn_grid();
    
    $name=new column;
    $name->template='<label><%name%></label>
    <br />
    <label><%date%></label>
    <br />
    <span><%comment%></span>';
    $grid->columns->append($name);
    if(isset($_POST['cmd']))
    {
        extract($_POST);
        $cmnt->insert_comment($pid,$name,$mail,strip_tags($comment,'<p><br>') );
        die($grid->show($cmnt->select_postcomments($pid)->fetch()));
    }
    ?>
    <br />
    <br />
    <div id="show">
    <?php
    echo $grid->show($cmnt->select_postcomments($pid)->fetch());
    ?>
    </div>
    <table id="cmnt">
        <tr>
            <td>نام</td>
            <td><input type="text" size="20" autocomplete="on" name="name" id="name" class="input-text"/></td>
        </tr>
        <tr>
            <td>پست الکترونیک</td>
            <td><input type="text" size="35" autocomplete="on" name="mail" id="mail" class="input-text"/></td>
        </tr>
        <tr>
            <td colspan="2">
            <label>متن کامنت</label><br />
            <textarea cols="50" name="comment" id="comment" class="input-text"></textarea>
            </td>
        </tr>
    </table>
    <br /><input type="submit" name="submit" id="submit" value="ثبت" class="button"/>
    <?php
}
 ?>
</div>
<?php	
$theme->render();
?>